#!/bin/bash

function network()
{
    local timeout=1
    local target=www.baidu.com
    local ret_code=`curl -I -s --connect-timeout ${timeout} ${target} -w %{http_code} | tail -n 1`

    if [ "x$ret_code" = "x200" ]
    then
        return 1
    else
        return 0
    fi
}

network
if [ $? -eq 0 ] 
then
    echo "Can't connect to Internet!"
    exit 1
else
    echo "Internet connected!"
fi

exit 0



